package com.game.gameshoppingcenter.controller;

import com.game.gameshoppingcenter.entities.Admin;
import com.game.gameshoppingcenter.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/Admin")
public class AdminController {
    @Autowired
    AdminService adminService;
    @RequestMapping("/admintoLogin")
    //进入登录界面
    public String tologin(@ModelAttribute("admin") Admin admin){

        return "AdminLogin/adminLogin";
    }
    @RequestMapping("/adminlogin")
    public String login(Model model, HttpServletRequest request){
         boolean flag=adminService.login(request);
         //flag中如果为空则刷新页面，不为空则到主页
        if(flag){
            return "Shoppingstore/shoppingstore";
        }else{
            model.addAttribute("errorMessage","用户名或密码错误！");
            return "AdminLogin/adminLogin";
        }
    }
}
